package com.jy.appmarket.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jy.appmarket.R;
import com.jy.appmarket.model.AppInfoModel;

public class DeskTopAppAdapter extends SimpleBaseAdapter<AppInfoModel> {

	protected static final String TAG = "DeskTopAppAdapter";

	public DeskTopAppAdapter(Context context) {
		super(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final AppInfoModel app = mList.get(position);
		ViewHolder holder;
		if (convertView == null) {
			convertView = getInflater().inflate(R.layout.item_desktop_app, parent, false);
			holder = new ViewHolder();
			holder.emptyView = convertView.findViewById(R.id.empty_view);
			//holder.background = convertView.findViewById(R.id.desktop_item_bg);
			holder.icon = convertView.findViewById(R.id.desktop_app_item_icon);
			holder.name = convertView.findViewById(R.id.desktop_app_item_name);
			holder.select = convertView.findViewById(R.id.desktop_app_item_select);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if(position < 4) {
			holder.emptyView.setVisibility(View.VISIBLE);
		} else {
			holder.emptyView.setVisibility(View.GONE);
		}
		holder.icon.setImageDrawable(app.getDrawable());
		holder.name.setText(app.getName());
		//holder.background.setBackgroundColor(app.isSelected() ? 0xFFD8D8D8 : Color.TRANSPARENT);
		holder.select.setImageResource(app.isSelected() ? R.drawable.selecte_icon : 0);
		return convertView;
	}

	private static class ViewHolder {
		private View emptyView;
//		private View background;
		private ImageView icon;
		private TextView name;
		private ImageView select;
	}
}
